﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class AdminDrug : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }        
    }

    private void Bind()
    {
        string sql = string.Format("select * from DrugDict");
        DataSet ds = DBHelper.GetDataSet(sql);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "ID" };
        GridView1.DataBind();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        Bind();
    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        Bind();
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[10].Attributes.Add("onclick", "return confirm('确定要删除吗')");
            //高亮显示
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
        }
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
        string sql = string.Format("delete from DrugDict where id={0}", id);
        DBHelper.GetNonQuery(sql);
        Bind();
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        Bind();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int id = Convert.ToInt32(this.GridView1.DataKeys[e.RowIndex].Value);
        TextBox ComName1 = (TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TxtComName");
        TextBox Name1 = (TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TxtName");
        TextBox Priceinfo1 = (TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TxtPriceinfo");
        TextBox Spec1 = (TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TxtSpec");
        TextBox IsspecialManage1 = (TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TxtIsspecialManage");
        TextBox InsuranceType1 = (TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TxtInsuranceType");
        TextBox Producearea1 = (TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TxtProducearea");
        TextBox AuthorizeSN1 = (TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TxtAuthorizeSN");
        string ComName = ComName1.Text;
        string Name = Name1.Text;
        string Proinfo = Priceinfo1.Text;
        string Spec = Spec1.Text;
        string IssMan = IsspecialManage1.Text;
        string InType = InsuranceType1.Text;
        string Pro = Producearea1.Text;
        string AuSN = AuthorizeSN1.Text;
        string sql = string.Format("update DrugDict set ComName='{0}',Name='{1}',Priceinfo={2},Spec='{3}',IsspecialManage='{4}',InsuranceType='{5}',Producearea='{6}',AuthorizeSN='{7}' where ID={8}", ComName, Name, Proinfo, Spec, IssMan, InType, Pro, AuSN,id);
        DBHelper.GetNonQuery(sql);
        this.GridView1.EditIndex = -1;
        Bind();
    }
}